package com.gkzf.ai.module.crm.controller.admin.creditReport;

import com.gkzf.ai.framework.common.pojo.CommonResult;
import com.gkzf.ai.framework.common.util.object.BeanUtils;
import com.gkzf.ai.module.crm.controller.admin.creditReport.vo.creditreportdetails.CreditReportDetailsRespVO;
import com.gkzf.ai.module.crm.controller.admin.creditReport.vo.creditreportdetails.CreditReportDetailsSaveReqVO;
import com.gkzf.ai.module.crm.service.creditReport.CreditReportAdmittanceConditionService;
import com.gkzf.ai.module.crm.service.creditReport.CreditReportDetailsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static com.gkzf.ai.framework.common.pojo.CommonResult.success;


@Tag(name = "管理后台 - CRM 征信报告详情")
@RestController
@RequestMapping("/crm/credit-report-details")
@Validated
public class CreditReportDetailsController {

    @Resource
    private CreditReportDetailsService creditReportDetailsService;


    @Resource
    private CreditReportAdmittanceConditionService creditReportAdmittanceConditionService;


    @PutMapping("/update")
    @Operation(summary = "更新CRM 征信报告详情")
    @PreAuthorize("@ss.hasPermission('crm:creditReportDetails:update')")
    public CommonResult<Boolean> updateCreditReportDetails(@Valid @RequestBody CreditReportDetailsSaveReqVO updateReqVO) {
        creditReportDetailsService.updateCreditReportDetails(updateReqVO);
        return success(true);
    }


    @GetMapping("/get")
    @Operation(summary = "获得CRM 征信报告详情")
    @Parameter(name = "creditBasicId", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('crm:creditReportDetails:query')")
    public CommonResult<CreditReportDetailsRespVO> getCreditReportDetails(@RequestParam("creditBasicId") Long creditBasicId) {
        CreditReportDetailsRespVO creditReportDetails = creditReportDetailsService.getCreditReportDetails(creditBasicId);
        return success(creditReportDetails);
    }

    @GetMapping("/getCreditAnalysis")
    @Operation(summary = "获得CRM 征信报告详情中AL分析结果")
    @Parameter(name = "creditBasicId", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('crm:creditReportDetails:update')")
    public CommonResult<String> getCreditAnalysis(@RequestParam("creditBasicId") Long creditBasicId) {
        CreditReportDetailsRespVO creditReportDetails = creditReportDetailsService.getCreditReportDetails(creditBasicId);
        String creditAnalysis = creditReportAdmittanceConditionService.analysisCreditReport(BeanUtils.toBean(creditReportDetails, CreditReportDetailsSaveReqVO.class));
        return success(creditAnalysis);
    }

}